<template>
  <view class="goodlist-good">
    <view class="left">
      <radio @click="changeRadio()" color="red" :checked="good.goods_state" v-if="showRadio" />
      <image :src="good.goods_small_logo||defaultPic" mode="" class="goods_pic"></image>
    </view>
    <view class="right">
      <view class="goods-name">
        {{good.goods_name}}
      </view>
      <view class="goods-info-box">
        <view class="goods-price">￥{{good.goods_price | toFixed}}</view>
        <uni-number-box v-if="showNumberBox" :value="good.goods_count" :min="1" @change="changeCount"></uni-number-box>
      </view>
    </view>
  </view>
</template>

<script>
  export default {
    name: "my-goods",
    props: {
      good: {
        type: Object
      },
      showRadio: {
        type: Boolean,
        default: false
      },
      showNumberBox: {
        type: Boolean,
        default: false
      },
    },
    data() {
      return {
        // 默认图片
        defaultPic: 'https://img3.doubanio.com/f/movie/8dd0c794499fe925ae2ae89ee30cd225750457b4/pics/movie/celebrity-default-medium.png'
      };
    },
    filters: {
      toFixed(num) {
        return Number(num).toFixed(2);
      }
    },
    methods: {
      // 改变单选框状态
      changeRadio() {
        // console.log(this.good);
        this.$emit('radioState', {
          goods_id: this.good.goods_id,
          goods_state: this.good.goods_state
        })
      },
      // 修改单件商品数量
      changeCount(e) {
        // console.log(e);
        this.$emit('onchangeCount', {
          goods_count: e,
          goods_id: this.good.goods_id,
        })
      }
    }
  }
</script>

<style lang="less">
  .goodlist-good {
    display: flex;
    padding: 10px 5px;
    border-bottom: 1px solid #f0f0f0;

    .left {
      margin-right: 5px;
      display: flex;
      align-items: center;

      .goods_pic {
        width: 100px;
        height: 100px;
        display: block;
      }
    }

    .right {
      display: flex;
      flex: 1;
      flex-direction: column;
      justify-content: space-between;

      .goods-name {
        font-size: 13px
      }

      .goods-info-box {
        display: flex;
        align-items: center;
        justify-content: space-between;

        .goods-price {
          font-size: 16px;
          color: #c00000;
        }
      }
    }
  }
</style>
